package dao;

import org.apache.ibatis.annotations.*;
import pojo.Lunbo;

import java.util.List;

@Mapper
public interface LunboMapper {

    @Insert("INSERT INTO lbt (image_url, title, sort_order, is_show) " +
            "VALUES (#{imageUrl}, #{title}, #{sortOrder}, #{isShow})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(Lunbo lunbo);

    @Select("SELECT * FROM lbt WHERE is_show = 1 ORDER BY sort_order ASC")
    List<Lunbo> findEnabled();

    @Select("SELECT * FROM lbt ORDER BY sort_order ASC")
    List<Lunbo> findAll();

    @Select("SELECT * FROM lbt WHERE id = #{id}")
    Lunbo findById(Integer id);

    @Update("UPDATE lbt SET " +
            "image_url = #{imageUrl}, " +
            "title = #{title}, " +
            "sort_order = #{sortOrder}, " +
            "is_show = #{isShow} " +
            "WHERE id = #{id}")
    int update(Lunbo lunbo);

    @Delete("DELETE FROM lbt WHERE id = #{id}")
    int deleteById(Integer id);
}